from django.db import models
from user.models import UserInfo

class Event(models.Model):
    user = models.ManyToManyField(UserInfo, verbose_name="用户信息") # 多对多
    name = models.CharField(max_length=100, unique=True, verbose_name="事件名称")
    status_choice = (
        (1, "未开始"),
        (2, "处理中"),
        (3, "已完成")
    )
    status = models.IntegerField(choices=status_choice, default=1, verbose_name="事件状态")
    grade_choice = (
        (1, "警告"),
        (2, "严重"),
        (3, "灾难")
    )
    grade = models.IntegerField(choices=grade_choice, default=1, verbose_name="事件等级")
    start_time = models.DateTimeField(auto_now_add=False, auto_now=False, verbose_name="开始时间")
    end_time = models.DateTimeField(auto_now_add=False, auto_now=False, verbose_name="结束时间")
    create_time = models.DateTimeField(auto_now_add=True, verbose_name="创建时间")

    class Meta:
        db_table = 'tools_event'
        verbose_name_plural = '事件管理'
        ordering = ('-id',)
    def __str__(self):
        return self.name

class Fault(models.Model):
    user = models.ManyToManyField(UserInfo, verbose_name="用户信息") # 多对多
    name = models.CharField(max_length=100, unique=True, verbose_name="故障名称")
    status_choice = (
        (1, "处理中"),
        (2, "已关闭"),
    )
    status = models.IntegerField(choices=status_choice, default=1, verbose_name="故障状态")
    grade_choice = (
        (1, "一级故障"),
        (2, "二级故障"),
        (3, "三级故障"),
        (4, "四级故障"),
        (5, "五级故障")
    )
    grade = models.IntegerField(choices=grade_choice, default=1, verbose_name="故障等级")
    upload = models.CharField(max_length=200, null=True, blank=True, verbose_name="故障报告")
    start_time = models.DateTimeField(auto_now_add=False, auto_now=False, verbose_name="开始时间")
    end_time = models.DateTimeField(auto_now_add=False, auto_now=False, verbose_name="结束时间")
    reason = models.TextField(blank=True, null=True, verbose_name="故障原因")
    summarize = models.TextField(blank=True, null=True, verbose_name="故障总结")
    create_time = models.DateTimeField(auto_now_add=True, verbose_name="创建时间")

    class Meta:
        db_table = 'tools_fault'
        verbose_name_plural = '故障管理'
        ordering = ('-id',)
    def __str__(self):
        return self.name


class Remind(models.Model):
    user = models.ManyToManyField(UserInfo, verbose_name="用户信息") # 多对多
    name = models.CharField(max_length=100, unique=True, verbose_name="提醒名称")
    type_choice = (
        (1, "工作提醒"),
        (2, "任务提醒"),
        (3, "其他提醒")
    )
    type = models.IntegerField(choices=type_choice, default=1, verbose_name="提醒类型")
    way_choice = (
        (1, "邮件"),
        (2, "钉钉"),
        (3, "企业微信")
    )
    way = models.IntegerField(choices=way_choice, default=1, verbose_name="提醒方式")
    dingding_webhook = models.CharField(max_length=200, null=True, blank=True, verbose_name="钉钉Webhook")
    weixin_webhook = models.CharField(max_length=200, null=True, blank=True, verbose_name="企业微信Webhook")
    status_choice = (
        (1, "已关闭"),
        (2, "已开启"),
    )
    status = models.IntegerField(choices=status_choice, default=1, verbose_name="状态")
    last_datetime = models.DateTimeField(blank=True, null=True, verbose_name="最后提醒时间")
    advance = models.CharField(max_length=10, null=True, blank=True, verbose_name="提前天数")
    note = models.TextField(blank=True, null=True, verbose_name="备注")
    create_time = models.DateTimeField(auto_now_add=True, verbose_name="创建时间")

    class Meta:
        db_table = 'tools_remind'
        verbose_name_plural = '提醒管理'
        ordering = ('-id',)
    def __str__(self):
        return self.name